-- msg_relic_rob_result
-- Create by panyl
-- 遗迹掠夺列表

return function(lpc)
    local para = lpc.result;

    -- 掠夺战斗结果
    trace("msg_relic_rob_result: ", tableToString(para));

    local relicList = ME.user.dbase:query("relic_rob_list", {});
    local target = para.target;

    local result        = para.result;
    local attackerInfo  = para.attacker;
    local defenserInfo  = para.defenser;
    local record        = para.record;

    local bonus = {};

    if result == 1 and para.scrap then
        bonus = para.bonus
    end

    -- 抛出事件给UISkyRelicMain界面
    EventMgr.fire(event.RECEIVE_ROB_RESULT, {["battleInfo"] =
        {"relic", target, SkyRelicM.getRelicElementPos("relic", target)}});

    -- 处理当前结果
    if relicList[target] then
        relicList[target]["result"] = result;

        if result == 1 then
            -- 增加连胜记录
            local winTimes = ME.user.dbase:query("relic_rob_win_times") or 0;
            ME.user.dbase:set("relic_rob_win_times", winTimes + 1);

            if SkyRelicM.getRobRelicExtraBonus(winTimes + 1) then
                -- 额外奖励
                bonus = table.append(bonus, SkyRelicM.getRobRelicExtraBonus(winTimes + 1));
            end

            -- 设置下次刷新时间
            local refreshTime = SkyRelicM.getRobRefreshTime();
            local nextRelicTime = ME.user.dbase:query("next_relic_time", 0);
            if type(nextRelicTime) == "number"
                and (nextRelicTime > refreshTime + TimeM.getServerTime()) then
                nextRelicTime = refreshTime + TimeM.getServerTime();
            elseif nextRelicTime <= 0 then
                nextRelicTime = refreshTime + TimeM.getServerTime();
            end

            ME.user.dbase:set("next_relic_time", nextRelicTime);

            -- 删除位置信息
            SkyRelicM.deleteRelicPosInfoByType("relic", target);
        end

        if para.fail_times then
            relicList[target]["fail_times"] = para.fail_times;
        end

        -- 记录掠夺时间
        if para.last_rob_time then
            relicList[target]["last_rob_time"] = para.last_rob_time;
        end

        ME.user.dbase:set("relic_rob_list", relicList);
    end

    -- 创建一个战场
    SkyCombatM.createBattle(attackerInfo, defenserInfo, result, record, bonus);

    -- 抛出刷新事件
    EventMgr.fire(event.RELIC_REFRESH_MAP, {});
end
